#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define sz size
#define all(x) x.begin(),x.end()
#define boost ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
// solve it
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const int inf = 1e9 + 7;
ll n, a, b, c;
ll hpp[26][26]={};
char names[7]={'A', 'B', 'C', 'T', 'D', 'S', 'H'};
ll mx=inf, mn=-inf, fr=0;
vector <char> cnt1, cnt2, cnt3;
void f(ll k) {
if(k==-1 && (cnt1.sz()==0 || cnt2.sz()==0 || cnt3.sz()==0)) {
int none;
none=1;
} else if(k==-1) {
ll lx=0, ln=0, lr=0;
for(ll i=0; i<cnt1.sz(); i++) {
for(ll j=0; j<cnt1.sz(); j++) {
if(hpp[cnt1[i]-'A'][cnt1[j]-'A'] != 0) lr++;
}
}
for(ll i=0; i<cnt2.sz(); i++) {
for(ll j=0; j<cnt2.sz(); j++) {
if(hpp[cnt2[i]-'A'][cnt2[j]-'A'] != 0) lr++;
}
}
for(ll i=0; i<cnt3.sz(); i++) {
for(ll j=0; j<cnt3.sz(); j++) {
if(hpp[cnt3[i]-'A'][cnt3[j]-'A'] != 0) lr++;
}
}
lx = max(a/cnt1.sz(), max(b/cnt2.sz(), c/cnt3.sz()));
ln = min(a/cnt1.sz(), min(b/cnt2.sz(), c/cnt3.sz()));
if((mx-mn) >= (lx-ln)) {
if(mx-mn==lx-ln) fr=max(fr,lr);
else fr=lr;
mx=lx, mn=ln;
}
} else {
for(int i=1; i<=3; i++) {
if(i==1) {
cnt1.pb(names[k]);
f(k-1);
cnt1.pop_back();
} else if(i==2) {
cnt2.pb(names[k]);
f(k-1);
cnt2.pop_back();
} else {
cnt3.pb(names[k]);
f(k-1);
cnt3.pop_back();
}
}
}
}
void solve() {
cin >> n;
for(int i=1; i<=n; i++) {
string s1,s2,s3;
cin >> s1 >> s2 >> s3;
if(s1=="Chapay") s1[0]='B';
if(s3=="Chapay") s3[0]='B';
hpp[s1[0]-'A'][s3[0]-'A']=1;
}
cin >> a >> b >> c;
f(6);
cout << mx-mn << " " << fr;
}
int main() {
boost;
srand(time(0));
//freopen("sparse.in", "r", stdin);
//freopen("sparse.out", "w", stdout);
int ttt;
ttt=1;
while(ttt--){
solve();
}
return 0;
}
905. Sort Array By Parity | 1351. Count Negative Numbers in a Sorted Matrix |
617. Merge Two Binary Trees | 1450. Number of Students Doing Homework at a Given Time |
700. Search in a Binary Search Tree | 590. N-ary Tree Postorder Traversal |
589. N-ary Tree Preorder Traversal | 1299. Replace Elements with Greatest Element on Right Side |
1768. Merge Strings Alternately | 561. Array Partition I |
1374. Generate a String With Characters That Have Odd Counts | 1822. Sign of the Product of an Array |
1464. Maximum Product of Two Elements in an Array | 1323. Maximum 69 Number |
832. Flipping an Image | 1295. Find Numbers with Even Number of Digits |
1704. Determine if String Halves Are Alike | 1732. Find the Highest Altitude |
709. To Lower Case | 1688. Count of Matches in Tournament |
1684. Count the Number of Consistent Strings | 1588. Sum of All Odd Length Subarrays |
1662. Check If Two String Arrays are Equivalent | 1832. Check if the Sentence Is Pangram |
1678. Goal Parser Interpretation | 1389. Create Target Array in the Given Order |
1313. Decompress Run-Length Encoded List | 1281. Subtract the Product and Sum of Digits of an Integer |
1342. Number of Steps to Reduce a Number to Zero | 1528. Shuffle String |